<!DOCTYPE html>
<html>6

<body>
    <p>Count numbers: <output id="result"></output></p>
    <button id="startWorkerBtn">Start Worker</button>
    <button id="stopWorkerBtn">Stop Worker</button>
    <input type="text" value="" />
    <script>
        let result = document.getElementById("result");
        let startWorkerBtn = document.getElementById("startWorkerBtn");
        let stopWorkerBtn = document.getElementById("stopWorkerBtn");

        let worker;

        function startWorker() {
            if (typeof Worker) {
                if (typeof(worker) === "undefined") {
                    worker = new Worker("worker.js");
                }
                worker.onmessage = function(e) {
                    result.innerHTML = e.data;
                };
            } else {
                result.innerHTML = "Sorry, your browser does not support Web Workers...";
            }
        }

        function stopWorker() {
            worker.terminate();
        }

        startWorkerBtn.addEventListener('click', (e) => {
            startWorker()
        })
        stopWorkerBtn.addEventListener('click', (e) => {
            stopWorker()
        })
    </script>
</body>

</html>